package app.purchase.a571xz.com.myandroidframe.httpservice.retrofit;


import io.reactivex.subscribers.ResourceSubscriber;

/**
 * 允许异步取消其订阅相关资源，节省内存而且是线程安全
 *
 * @param <T>
 */
public abstract class ApiSubscriberCallback<T> extends ResourceSubscriber<T> {
    @Override
    public void onNext(T t) {
        onResult(t);
    }

    @Override
    public void onError(Throwable t) {
        onCompleted();
        onFailure(t);
    }

    @Override
    public void onComplete() {
        onCompleted();
    }

    //请求成功后执行
    public abstract void onResult(T t);

    //请求失败后执行
    public abstract void onFailure(Throwable t);

    //请求最后需要执行
    public abstract void onCompleted();

}
